{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "from deeptables.models import deeptable,deepnets\n",
    "from sklearn.model_selection import train_test_split\n",
    "from sklearn import datasets\n",
    "from sklearn.metrics import mean_squared_error, r2_score\n",
    "import pandas as pd\n",
    "import numpy as np"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Target column type is float, so inferred as a [regression] task.\n",
      "Preparing features taken 0.007421970367431641s\n",
      "Imputation taken 0.030076980590820312s\n",
      "Categorical encoding taken 1.7881393432617188e-05s\n",
      "Injected a callback [EarlyStopping]. monitor:val_RootMeanSquaredError, patience:5, mode:min\n",
      ">>>>>>>>>>>>>>>>>>>>>> Model Desc <<<<<<<<<<<<<<<<<<<<<<< \n",
      "---------------------------------------------------------\n",
      "inputs:\n",
      "---------------------------------------------------------\n",
      "['all_categorical_vars: (0)', 'input_continuous_all: (13)']\n",
      "---------------------------------------------------------\n",
      "embeddings:\n",
      "---------------------------------------------------------\n",
      "input_dims: []\n",
      "output_dims: []\n",
      "dropout: 0.3\n",
      "---------------------------------------------------------\n",
      "dense: dropout: 0\n",
      "batch_normalization: False\n",
      "---------------------------------------------------------\n",
      "concat_embed_dense: shape: (None, 13)\n",
      "---------------------------------------------------------\n",
      "nets: ['dnn_nets']\n",
      "---------------------------------------------------------\n",
      "dnn: input_shape (None, 13), output_shape (None, 256)\n",
      "---------------------------------------------------------\n",
      "stacking_op: add\n",
      "---------------------------------------------------------\n",
      "output: activation: None, output_shape: (None, 1), use_bias: True\n",
      "loss: mse\n",
      "optimizer: Adam\n",
      "---------------------------------------------------------\n",
      "\n",
      "Train on 323 samples, validate on 81 samples\n",
      "Epoch 1/100\n",
      "323/323 [==============================] - 12s 38ms/sample - loss: 605.9220 - RootMeanSquaredError: 24.6155 - val_loss: 2046.0961 - val_RootMeanSquaredError: 45.2338\n",
      "Epoch 2/100\n",
      "323/323 [==============================] - 0s 964us/sample - loss: 571.5709 - RootMeanSquaredError: 23.9075 - val_loss: 2034.1385 - val_RootMeanSquaredError: 45.1014\n",
      "Epoch 3/100\n",
      "323/323 [==============================] - 1s 2ms/sample - loss: 546.7905 - RootMeanSquaredError: 23.3836 - val_loss: 1991.6023 - val_RootMeanSquaredError: 44.6274\n",
      "Epoch 4/100\n",
      "323/323 [==============================] - 0s 1ms/sample - loss: 522.4116 - RootMeanSquaredError: 22.8563 - val_loss: 1871.0498 - val_RootMeanSquaredError: 43.2556\n",
      "Epoch 5/100\n",
      "323/323 [==============================] - 1s 2ms/sample - loss: 504.7474 - RootMeanSquaredError: 22.4666 - val_loss: 1714.3779 - val_RootMeanSquaredError: 41.4050\n",
      "Epoch 6/100\n",
      "323/323 [==============================] - 0s 1ms/sample - loss: 483.3415 - RootMeanSquaredError: 21.9850 - val_loss: 1534.0557 - val_RootMeanSquaredError: 39.1670\n",
      "Epoch 7/100\n",
      "323/323 [==============================] - 1s 2ms/sample - loss: 462.9288 - RootMeanSquaredError: 21.5158 - val_loss: 1348.6862 - val_RootMeanSquaredError: 36.7245\n",
      "Epoch 8/100\n",
      "323/323 [==============================] - 0s 1ms/sample - loss: 441.1551 - RootMeanSquaredError: 21.0037 - val_loss: 1167.8405 - val_RootMeanSquaredError: 34.1737\n",
      "Epoch 9/100\n",
      "323/323 [==============================] - 0s 1ms/sample - loss: 431.4087 - RootMeanSquaredError: 20.7704 - val_loss: 1009.5242 - val_RootMeanSquaredError: 31.7730\n",
      "Epoch 10/100\n",
      "323/323 [==============================] - 0s 1ms/sample - loss: 413.8210 - RootMeanSquaredError: 20.3426 - val_loss: 854.7227 - val_RootMeanSquaredError: 29.2356\n",
      "Epoch 11/100\n",
      "323/323 [==============================] - 1s 2ms/sample - loss: 397.7755 - RootMeanSquaredError: 19.9443 - val_loss: 720.6437 - val_RootMeanSquaredError: 26.8448\n",
      "Epoch 12/100\n",
      "323/323 [==============================] - 0s 937us/sample - loss: 382.0893 - RootMeanSquaredError: 19.5471 - val_loss: 608.5705 - val_RootMeanSquaredError: 24.6692\n",
      "Epoch 13/100\n",
      "323/323 [==============================] - 0s 1ms/sample - loss: 365.1345 - RootMeanSquaredError: 19.1085 - val_loss: 516.7172 - val_RootMeanSquaredError: 22.7314\n",
      "Epoch 14/100\n",
      "323/323 [==============================] - 1s 2ms/sample - loss: 349.9614 - RootMeanSquaredError: 18.7073 - val_loss: 441.2815 - val_RootMeanSquaredError: 21.0067\n",
      "Epoch 15/100\n",
      "323/323 [==============================] - 0s 827us/sample - loss: 336.3764 - RootMeanSquaredError: 18.3406 - val_loss: 380.6067 - val_RootMeanSquaredError: 19.5091\n",
      "Epoch 16/100\n",
      "323/323 [==============================] - 0s 1ms/sample - loss: 327.6844 - RootMeanSquaredError: 18.1021 - val_loss: 333.7563 - val_RootMeanSquaredError: 18.2690\n",
      "Epoch 17/100\n",
      "323/323 [==============================] - 0s 858us/sample - loss: 313.4420 - RootMeanSquaredError: 17.7043 - val_loss: 293.7809 - val_RootMeanSquaredError: 17.1400\n",
      "Epoch 18/100\n",
      "323/323 [==============================] - 1s 2ms/sample - loss: 299.6084 - RootMeanSquaredError: 17.3092 - val_loss: 259.2422 - val_RootMeanSquaredError: 16.1010\n",
      "Epoch 19/100\n",
      "323/323 [==============================] - 0s 1ms/sample - loss: 286.7559 - RootMeanSquaredError: 16.9339 - val_loss: 232.2546 - val_RootMeanSquaredError: 15.2399\n",
      "Epoch 20/100\n",
      "323/323 [==============================] - 0s 856us/sample - loss: 278.2726 - RootMeanSquaredError: 16.6815 - val_loss: 209.3416 - val_RootMeanSquaredError: 14.4686\n",
      "Epoch 21/100\n",
      "323/323 [==============================] - 0s 906us/sample - loss: 265.8978 - RootMeanSquaredError: 16.3064 - val_loss: 195.7728 - val_RootMeanSquaredError: 13.9919\n",
      "Epoch 22/100\n",
      "323/323 [==============================] - 1s 2ms/sample - loss: 255.3743 - RootMeanSquaredError: 15.9804 - val_loss: 184.9865 - val_RootMeanSquaredError: 13.6010\n",
      "Epoch 23/100\n",
      "323/323 [==============================] - 0s 852us/sample - loss: 241.2139 - RootMeanSquaredError: 15.5311 - val_loss: 177.0754 - val_RootMeanSquaredError: 13.3070\n",
      "Epoch 24/100\n",
      "323/323 [==============================] - 0s 933us/sample - loss: 235.9942 - RootMeanSquaredError: 15.3621 - val_loss: 172.0263 - val_RootMeanSquaredError: 13.1159\n",
      "Epoch 25/100\n",
      "323/323 [==============================] - 1s 2ms/sample - loss: 221.1544 - RootMeanSquaredError: 14.8713 - val_loss: 168.7070 - val_RootMeanSquaredError: 12.9887\n",
      "Epoch 26/100\n",
      "323/323 [==============================] - 0s 1ms/sample - loss: 208.3202 - RootMeanSquaredError: 14.4333 - val_loss: 166.8124 - val_RootMeanSquaredError: 12.9156\n",
      "Epoch 27/100\n",
      "323/323 [==============================] - 0s 1ms/sample - loss: 199.8627 - RootMeanSquaredError: 14.1373 - val_loss: 163.9167 - val_RootMeanSquaredError: 12.8030\n",
      "Epoch 28/100\n",
      "323/323 [==============================] - 0s 954us/sample - loss: 193.0825 - RootMeanSquaredError: 13.8954 - val_loss: 163.0235 - val_RootMeanSquaredError: 12.7681\n",
      "Epoch 29/100\n",
      "323/323 [==============================] - 0s 2ms/sample - loss: 181.1249 - RootMeanSquaredError: 13.4583 - val_loss: 161.1587 - val_RootMeanSquaredError: 12.6948\n",
      "Epoch 30/100\n",
      "323/323 [==============================] - 0s 956us/sample - loss: 171.8233 - RootMeanSquaredError: 13.1081 - val_loss: 159.5110 - val_RootMeanSquaredError: 12.6298\n",
      "Epoch 31/100\n",
      "323/323 [==============================] - 0s 1ms/sample - loss: 168.4751 - RootMeanSquaredError: 12.9798 - val_loss: 160.5759 - val_RootMeanSquaredError: 12.6719\n",
      "Epoch 32/100\n",
      "323/323 [==============================] - 0s 957us/sample - loss: 157.9799 - RootMeanSquaredError: 12.5690 - val_loss: 161.2535 - val_RootMeanSquaredError: 12.6986\n",
      "Epoch 33/100\n",
      "323/323 [==============================] - 0s 951us/sample - loss: 144.2017 - RootMeanSquaredError: 12.0084 - val_loss: 161.4132 - val_RootMeanSquaredError: 12.7048\n",
      "Epoch 34/100\n",
      "323/323 [==============================] - 0s 1ms/sample - loss: 134.2196 - RootMeanSquaredError: 11.5853 - val_loss: 160.0576 - val_RootMeanSquaredError: 12.6514\n",
      "Epoch 35/100\n",
      "323/323 [==============================] - 0s 957us/sample - loss: 129.6590 - RootMeanSquaredError: 11.3868 - val_loss: 158.4490 - val_RootMeanSquaredError: 12.5877\n",
      "Epoch 36/100\n",
      "323/323 [==============================] - 0s 1ms/sample - loss: 123.8127 - RootMeanSquaredError: 11.1271 - val_loss: 155.9650 - val_RootMeanSquaredError: 12.4886\n",
      "Epoch 37/100\n",
      "323/323 [==============================] - 0s 2ms/sample - loss: 117.3270 - RootMeanSquaredError: 10.8318 - val_loss: 153.5680 - val_RootMeanSquaredError: 12.3923\n",
      "Epoch 38/100\n",
      "323/323 [==============================] - 0s 1ms/sample - loss: 111.1538 - RootMeanSquaredError: 10.5429 - val_loss: 153.4633 - val_RootMeanSquaredError: 12.3880\n",
      "Epoch 39/100\n",
      "323/323 [==============================] - 0s 1ms/sample - loss: 104.7878 - RootMeanSquaredError: 10.2366 - val_loss: 154.0259 - val_RootMeanSquaredError: 12.4107\n",
      "Epoch 40/100\n",
      "323/323 [==============================] - 0s 1ms/sample - loss: 102.2709 - RootMeanSquaredError: 10.1129 - val_loss: 154.9080 - val_RootMeanSquaredError: 12.4462\n",
      "Epoch 41/100\n",
      "323/323 [==============================] - 0s 1ms/sample - loss: 91.6848 - RootMeanSquaredError: 9.5752 - val_loss: 154.5146 - val_RootMeanSquaredError: 12.4304\n",
      "Epoch 42/100\n",
      "323/323 [==============================] - 0s 2ms/sample - loss: 87.2854 - RootMeanSquaredError: 9.3427 - val_loss: 153.7065 - val_RootMeanSquaredError: 12.3978\n",
      "Epoch 43/100\n",
      "323/323 [==============================] - 0s 1ms/sample - loss: 80.4338 - RootMeanSquaredError: 8.9685 - val_loss: 153.3566 - val_RootMeanSquaredError: 12.3837\n",
      "Epoch 44/100\n",
      "323/323 [==============================] - 0s 953us/sample - loss: 73.6163 - RootMeanSquaredError: 8.5800 - val_loss: 153.3305 - val_RootMeanSquaredError: 12.3827\n",
      "Epoch 45/100\n",
      "323/323 [==============================] - 0s 883us/sample - loss: 68.7992 - RootMeanSquaredError: 8.2945 - val_loss: 152.5888 - val_RootMeanSquaredError: 12.3527\n",
      "Epoch 46/100\n",
      "323/323 [==============================] - 0s 901us/sample - loss: 70.3974 - RootMeanSquaredError: 8.3903 - val_loss: 150.6198 - val_RootMeanSquaredError: 12.2727\n",
      "Epoch 47/100\n",
      "323/323 [==============================] - 0s 851us/sample - loss: 63.3727 - RootMeanSquaredError: 7.9607 - val_loss: 147.0488 - val_RootMeanSquaredError: 12.1264\n",
      "Epoch 48/100\n",
      "323/323 [==============================] - 0s 939us/sample - loss: 54.6132 - RootMeanSquaredError: 7.3901 - val_loss: 141.9269 - val_RootMeanSquaredError: 11.9133\n",
      "Epoch 49/100\n",
      "323/323 [==============================] - 0s 1ms/sample - loss: 51.2469 - RootMeanSquaredError: 7.1587 - val_loss: 136.4763 - val_RootMeanSquaredError: 11.6823\n",
      "Epoch 50/100\n",
      "323/323 [==============================] - 0s 1ms/sample - loss: 48.6791 - RootMeanSquaredError: 6.9770 - val_loss: 131.8039 - val_RootMeanSquaredError: 11.4806\n",
      "Epoch 51/100\n",
      "323/323 [==============================] - 0s 1ms/sample - loss: 47.7466 - RootMeanSquaredError: 6.9099 - val_loss: 126.5171 - val_RootMeanSquaredError: 11.2480\n",
      "Epoch 52/100\n",
      "323/323 [==============================] - 0s 889us/sample - loss: 43.9470 - RootMeanSquaredError: 6.6293 - val_loss: 120.2846 - val_RootMeanSquaredError: 10.9674\n",
      "Epoch 53/100\n",
      "323/323 [==============================] - 0s 1ms/sample - loss: 43.5980 - RootMeanSquaredError: 6.6029 - val_loss: 114.1518 - val_RootMeanSquaredError: 10.6842\n",
      "Epoch 54/100\n",
      "323/323 [==============================] - 0s 917us/sample - loss: 39.8438 - RootMeanSquaredError: 6.3122 - val_loss: 108.9022 - val_RootMeanSquaredError: 10.4356\n",
      "Epoch 55/100\n",
      "323/323 [==============================] - 0s 1ms/sample - loss: 36.4382 - RootMeanSquaredError: 6.0364 - val_loss: 104.6754 - val_RootMeanSquaredError: 10.2311\n",
      "Epoch 56/100\n",
      "323/323 [==============================] - 0s 1ms/sample - loss: 36.4697 - RootMeanSquaredError: 6.0390 - val_loss: 101.1064 - val_RootMeanSquaredError: 10.0552\n",
      "Epoch 57/100\n",
      "323/323 [==============================] - 0s 872us/sample - loss: 32.1881 - RootMeanSquaredError: 5.6735 - val_loss: 97.4467 - val_RootMeanSquaredError: 9.8715\n",
      "Epoch 58/100\n",
      "323/323 [==============================] - 1s 2ms/sample - loss: 29.1757 - RootMeanSquaredError: 5.4015 - val_loss: 93.6598 - val_RootMeanSquaredError: 9.6778\n",
      "Epoch 59/100\n",
      "323/323 [==============================] - 0s 1ms/sample - loss: 29.8114 - RootMeanSquaredError: 5.4600 - val_loss: 90.1570 - val_RootMeanSquaredError: 9.4951\n",
      "Epoch 60/100\n",
      "323/323 [==============================] - 0s 1ms/sample - loss: 25.5612 - RootMeanSquaredError: 5.0558 - val_loss: 85.9094 - val_RootMeanSquaredError: 9.2687\n",
      "Epoch 61/100\n",
      "323/323 [==============================] - 0s 719us/sample - loss: 25.7334 - RootMeanSquaredError: 5.0728 - val_loss: 81.3344 - val_RootMeanSquaredError: 9.0186\n",
      "Epoch 62/100\n",
      "323/323 [==============================] - 0s 1ms/sample - loss: 25.2143 - RootMeanSquaredError: 5.0214 - val_loss: 77.3613 - val_RootMeanSquaredError: 8.7955\n",
      "Epoch 63/100\n",
      "323/323 [==============================] - 0s 1ms/sample - loss: 27.1084 - RootMeanSquaredError: 5.2066 - val_loss: 74.6633 - val_RootMeanSquaredError: 8.6408\n",
      "Epoch 64/100\n",
      "323/323 [==============================] - 0s 757us/sample - loss: 22.1535 - RootMeanSquaredError: 4.7067 - val_loss: 72.1315 - val_RootMeanSquaredError: 8.4930\n",
      "Epoch 65/100\n",
      "323/323 [==============================] - 0s 921us/sample - loss: 21.4104 - RootMeanSquaredError: 4.6271 - val_loss: 69.3443 - val_RootMeanSquaredError: 8.3273\n",
      "Epoch 66/100\n",
      "323/323 [==============================] - 0s 842us/sample - loss: 20.9214 - RootMeanSquaredError: 4.5740 - val_loss: 67.0920 - val_RootMeanSquaredError: 8.1910\n",
      "Epoch 67/100\n",
      "323/323 [==============================] - 0s 816us/sample - loss: 23.5664 - RootMeanSquaredError: 4.8545 - val_loss: 64.4917 - val_RootMeanSquaredError: 8.0307\n",
      "Epoch 68/100\n",
      "323/323 [==============================] - 0s 748us/sample - loss: 17.9186 - RootMeanSquaredError: 4.2330 - val_loss: 61.8687 - val_RootMeanSquaredError: 7.8657\n",
      "Epoch 69/100\n",
      "323/323 [==============================] - 0s 791us/sample - loss: 17.1121 - RootMeanSquaredError: 4.1367 - val_loss: 58.9191 - val_RootMeanSquaredError: 7.6759\n",
      "Epoch 70/100\n",
      "323/323 [==============================] - 0s 780us/sample - loss: 19.5254 - RootMeanSquaredError: 4.4188 - val_loss: 55.8115 - val_RootMeanSquaredError: 7.4707\n",
      "Epoch 71/100\n",
      "323/323 [==============================] - 0s 599us/sample - loss: 17.0859 - RootMeanSquaredError: 4.1335 - val_loss: 53.3926 - val_RootMeanSquaredError: 7.3070\n",
      "Epoch 72/100\n",
      "323/323 [==============================] - 0s 591us/sample - loss: 16.6987 - RootMeanSquaredError: 4.0864 - val_loss: 50.8082 - val_RootMeanSquaredError: 7.1280\n",
      "Epoch 73/100\n",
      "323/323 [==============================] - 0s 589us/sample - loss: 20.0947 - RootMeanSquaredError: 4.4827 - val_loss: 48.2678 - val_RootMeanSquaredError: 6.9475\n",
      "Epoch 74/100\n",
      "323/323 [==============================] - 0s 689us/sample - loss: 16.7347 - RootMeanSquaredError: 4.0908 - val_loss: 45.9408 - val_RootMeanSquaredError: 6.7780\n",
      "Epoch 75/100\n",
      "323/323 [==============================] - 0s 596us/sample - loss: 16.9892 - RootMeanSquaredError: 4.1218 - val_loss: 43.9393 - val_RootMeanSquaredError: 6.6287\n",
      "Epoch 76/100\n",
      "323/323 [==============================] - 0s 612us/sample - loss: 14.7913 - RootMeanSquaredError: 3.8459 - val_loss: 42.3081 - val_RootMeanSquaredError: 6.5045\n",
      "Epoch 77/100\n",
      "323/323 [==============================] - 0s 581us/sample - loss: 14.3162 - RootMeanSquaredError: 3.7837 - val_loss: 41.3012 - val_RootMeanSquaredError: 6.4266\n",
      "Epoch 78/100\n",
      "323/323 [==============================] - 0s 591us/sample - loss: 16.5142 - RootMeanSquaredError: 4.0638 - val_loss: 39.9339 - val_RootMeanSquaredError: 6.3193\n",
      "Epoch 79/100\n",
      "323/323 [==============================] - 0s 622us/sample - loss: 14.6960 - RootMeanSquaredError: 3.8335 - val_loss: 38.2221 - val_RootMeanSquaredError: 6.1824\n",
      "Epoch 80/100\n",
      "323/323 [==============================] - 0s 607us/sample - loss: 15.2912 - RootMeanSquaredError: 3.9104 - val_loss: 36.4017 - val_RootMeanSquaredError: 6.0334\n",
      "Epoch 81/100\n",
      "323/323 [==============================] - 0s 588us/sample - loss: 18.1091 - RootMeanSquaredError: 4.2555 - val_loss: 34.7171 - val_RootMeanSquaredError: 5.8921\n",
      "Epoch 82/100\n",
      "323/323 [==============================] - 0s 586us/sample - loss: 15.5136 - RootMeanSquaredError: 3.9387 - val_loss: 33.7083 - val_RootMeanSquaredError: 5.8059\n",
      "Epoch 83/100\n",
      "323/323 [==============================] - 0s 579us/sample - loss: 16.0667 - RootMeanSquaredError: 4.0083 - val_loss: 32.5816 - val_RootMeanSquaredError: 5.7080\n",
      "Epoch 84/100\n",
      "323/323 [==============================] - 0s 706us/sample - loss: 16.0565 - RootMeanSquaredError: 4.0071 - val_loss: 31.5726 - val_RootMeanSquaredError: 5.6190\n",
      "Epoch 85/100\n",
      "323/323 [==============================] - 0s 808us/sample - loss: 13.9224 - RootMeanSquaredError: 3.7313 - val_loss: 30.5976 - val_RootMeanSquaredError: 5.5315\n",
      "Epoch 86/100\n",
      "323/323 [==============================] - 0s 543us/sample - loss: 14.1963 - RootMeanSquaredError: 3.7678 - val_loss: 29.9311 - val_RootMeanSquaredError: 5.4709\n",
      "Epoch 87/100\n",
      "323/323 [==============================] - 0s 719us/sample - loss: 14.1291 - RootMeanSquaredError: 3.7589 - val_loss: 29.6018 - val_RootMeanSquaredError: 5.4407\n",
      "Epoch 88/100\n",
      "323/323 [==============================] - 0s 632us/sample - loss: 12.7976 - RootMeanSquaredError: 3.5774 - val_loss: 29.6609 - val_RootMeanSquaredError: 5.4462\n",
      "Epoch 89/100\n",
      "323/323 [==============================] - 0s 681us/sample - loss: 13.9205 - RootMeanSquaredError: 3.7310 - val_loss: 29.0654 - val_RootMeanSquaredError: 5.3912\n",
      "Epoch 90/100\n",
      "323/323 [==============================] - 0s 732us/sample - loss: 14.3736 - RootMeanSquaredError: 3.7913 - val_loss: 27.9612 - val_RootMeanSquaredError: 5.2878\n",
      "Epoch 91/100\n",
      "323/323 [==============================] - 0s 668us/sample - loss: 14.8850 - RootMeanSquaredError: 3.8581 - val_loss: 26.9350 - val_RootMeanSquaredError: 5.1899\n",
      "Epoch 92/100\n",
      "323/323 [==============================] - 0s 663us/sample - loss: 15.7931 - RootMeanSquaredError: 3.9741 - val_loss: 25.7510 - val_RootMeanSquaredError: 5.0745\n",
      "Epoch 93/100\n",
      "323/323 [==============================] - 0s 809us/sample - loss: 12.6705 - RootMeanSquaredError: 3.5596 - val_loss: 24.5900 - val_RootMeanSquaredError: 4.9588\n",
      "Epoch 94/100\n",
      "323/323 [==============================] - 0s 717us/sample - loss: 15.9293 - RootMeanSquaredError: 3.9911 - val_loss: 23.7771 - val_RootMeanSquaredError: 4.8762\n",
      "Epoch 95/100\n",
      "323/323 [==============================] - 0s 718us/sample - loss: 13.0488 - RootMeanSquaredError: 3.6123 - val_loss: 23.1096 - val_RootMeanSquaredError: 4.8072\n",
      "Epoch 96/100\n",
      "323/323 [==============================] - 0s 760us/sample - loss: 13.1327 - RootMeanSquaredError: 3.6239 - val_loss: 22.5083 - val_RootMeanSquaredError: 4.7443\n",
      "Epoch 97/100\n",
      "323/323 [==============================] - 0s 741us/sample - loss: 12.3810 - RootMeanSquaredError: 3.5187 - val_loss: 22.1122 - val_RootMeanSquaredError: 4.7024\n",
      "Epoch 98/100\n",
      "323/323 [==============================] - 0s 642us/sample - loss: 12.7828 - RootMeanSquaredError: 3.5753 - val_loss: 21.9113 - val_RootMeanSquaredError: 4.6809\n",
      "Epoch 99/100\n",
      "323/323 [==============================] - 0s 791us/sample - loss: 12.2820 - RootMeanSquaredError: 3.5046 - val_loss: 21.6865 - val_RootMeanSquaredError: 4.6569\n",
      "Epoch 100/100\n",
      "323/323 [==============================] - 0s 595us/sample - loss: 11.2690 - RootMeanSquaredError: 3.3569 - val_loss: 21.3812 - val_RootMeanSquaredError: 4.6240\n",
      "Model has been saved to:dt_output/dt_20201019 132220_dnn_nets/dnn_nets.h5\n"
     ]
    }
   ],
   "source": [
    "boston_dataset = datasets.load_boston()\n",
    "\n",
    "df_train = pd.DataFrame(boston_dataset.data)\n",
    "df_train.columns = boston_dataset.feature_names\n",
    "y = pd.Series(boston_dataset.target)\n",
    "X = df_train\n",
    "\n",
    "conf = deeptable.ModelConfig(\n",
    "    metrics=['RootMeanSquaredError'], \n",
    "    nets=['dnn_nets'],\n",
    "    dnn_params={\n",
    "        'hidden_units': ((256, 0.3, True), (256, 0.3, True)),\n",
    "        'dnn_activation': 'relu',\n",
    "    },\n",
    "    earlystopping_patience=5,\n",
    ")\n",
    "\n",
    "dt = deeptable.DeepTable(config=conf)\n",
    "\n",
    "X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)\n",
    "model, history = dt.fit(X_train, y_train, epochs=100)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'loss': 29.785655975341797, 'rootmeansquarederror': 5.4576235}\n"
     ]
    }
   ],
   "source": [
    "result = dt.evaluate(X_test, y_test)\n",
    "print(result)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "dt_preds = dt.predict_proba(X_test, batch_size=10)\n",
    "#dt_preds"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The model performance for testing set\n",
      "--------------------------------------\n",
      "RMSE is 5.457623504737336\n",
      "R2 score is 0.5938344779738993\n"
     ]
    }
   ],
   "source": [
    "# root mean square error of the model\n",
    "rmse = (np.sqrt(mean_squared_error(y_test, dt_preds)))\n",
    "\n",
    "# r-squared score of the model\n",
    "r2 = r2_score(y_test, dt_preds)\n",
    "\n",
    "print(\"The model performance for testing set\")\n",
    "print(\"--------------------------------------\")\n",
    "print('RMSE is {}'.format(rmse))\n",
    "print('R2 score is {}'.format(r2))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
